<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    class CustomTagMatcher {
      constructor(tag) {
        this.tag = tag
      }
      [Symbol.match](string) {
        const pattern = new RegExp(`<${this.tag}>(.*?)</${this.tag}>`, 'g')
        const matches = []
        let match;
        while ((match = pattern.exec(string)) !== null) {
          matches.push(match[1])
        }
        return matches.length > 0 ? matches : null
      }
    }
    const customTagMatcher = new CustomTagMatcher("custom")
    const text = "<custom>content1</custom> some text <custom>content2</custom>"
    console.log(text.match(customTagMatcher))
  </script>
</body>

</html>